<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){

    	$model= D ('Goods');
    	$goodslist=$model->getAll();

    	foreach ($goodslist as &$value) 
        {	
    		$value['giname']='/public/Uploads/'.$this->substr($value['giname']).'230_'.$value['giname'];
    	}
    	

    //---------电脑Intel，1-4 5-8 切割配合前台JS--------
        $newones=$this->newnoe($goodslist);
        $newone=array_slice($newones, 0,4);
        $newtwo=array_slice($newones, 4,4);
        $this->assign('newone',$newone);
        $this->assign('newtwo',$newtwo);
        // var_dump($newone);
        // var_dump($newtwo);       
    //-----------------------结束-----------------------

    //---------手机iPhonel，1-4 5-8 切割配合前台JS--------
        $iPhone=$this->iPhone($goodslist);
        // var_dump($iPhone);
        $iPhone1=array_slice($iPhone, 0,4);
        $iPhone5=array_slice($iPhone, 4,4);
        $this->assign('iPhone1',$iPhone1);
        $this->assign('iPhone5',$iPhone5);
        // var_dump($iPhone1);
        // var_dump($iPhone5);       
    //-
        $this->display();
    }


    //拼接图片完整目录  接收图片名
	 private function substr($filename){

	 	return substr($filename,0,4).'/'.substr($filename,4,2).'/'.substr($filename,6,2).'/';
	 }

//+------前台页面显示新品--(电脑类)---一次只能遍历4个,带有JS效果需要遍历2次-----------------
	public function newnoe($goodslist){
	 	
    	$Intel=[];//新品 状态=1
    	foreach ($goodslist as $key=>$val) 
    		{		
    			if($val['cname']=='电脑') //新品
    			{
    				 $newones[]=$val;			 
    			}
    		}
            // var_dump($newones);
            return  $newones;

    	//用于前台JS翻页滚动 每次滚动4条 
    /*	$newone=array_slice($newones, 0,4);
        $newtwo=array_slice($newones, 4,4);
        $this->assign('newone',$newone);
        $this->assign('newtwo',$newtwo);*/
    	
    	// var_dump($newtwo);
    	// var_dump($newone);	

	 }
//+---------------------------(手机类)-----新品---结束--------------------------------

//+------前台页面显示新品--(手机类)---一次只能遍历4个,带有JS效果需要遍历2次-----------------
    public function iPhone($goodslist){
        
        $iPhone=[];//新品 状态=1
        foreach ($goodslist as $key=>$valu) 
            {       
                if($valu['cname']=='iPhone手机') //新品
                {
                     $iPhone[]=$valu;            
                }
            }
            // var_dump($iPhone);
            return  $iPhone;

        //用于前台JS翻页滚动 每次滚动4条 
    /*  $newone=array_slice($newones, 0,4);
        $newtwo=array_slice($newones, 4,4);
        $this->assign('newone',$newone);
        $this->assign('newtwo',$newtwo);*/
        
        // var_dump($newtwo);
        // var_dump($newone);   

     }
//+---------------------------(电脑类)-----新品---结束--------------------------------










}	